//
//  UIGridView.h
//  GridViewUsingTableView
//
//  Created by Manoj Babu on 23/09/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "UIGridViewCell.h"

@class UIGridPath;
@class UIGridViewRow;

@protocol UIGridViewDelegate;
@protocol UIGridViewDataSource;

@protocol UIGridViewRowDelegate <NSObject>
@required
-(void)gridViewRow:(UIGridViewRow *)row didSelectCellAtGridPath:(UIGridPath *)gridPath;
@end


@interface UIGridView : UIView <UITableViewDelegate, UITableViewDataSource, UIGridViewRowDelegate>{
    
    id<UIGridViewDelegate> delegate;
    id<UIGridViewDataSource> dataSource;
    float cellHeight;
    float cellWidth;
    
@private
    UITableView *_tableView;
    int nRows, nColumns, nCells;
    float gap, rHeight;
    UIGridViewRow *_dequeuedRow;
    
}

@property(nonatomic, assign) id<UIGridViewDelegate> delegate;
@property(nonatomic, assign) id<UIGridViewDataSource> dataSource;
@property (nonatomic) float cellHeight;
@property (nonatomic) float cellWidth;

-(UIGridViewCell *)dequeueCellAtGridPath:(UIGridPath *)gridPath;
-(void)reloadData;
@end

@protocol UIGridViewDelegate <NSObject>

-(void)didSelectCellAtGridPath:(UIGridPath *)gridPath;

@end

@protocol UIGridViewDataSource <NSObject>

@required
-(NSUInteger)numberOfItemsInGridView:(UIGridView *)gridView;
-(UIGridViewCell *)gridView:(UIGridView *)gridView cellForIndexAtGridPath:(UIGridPath *)gridPath;

@end


@interface UIGridPath : NSObject {
    int row;
    int column;
    int index;
}

@property (nonatomic) int row;
@property (nonatomic) int column;
@property (nonatomic) int index;

-(id)initWithRow:(NSInteger)_row column:(NSInteger)_column index:(NSInteger)_index;

@end

@interface UIGridViewRow : UITableViewCell <UIGridViewCellDelegate>{
    int row;
    id<UIGridViewRowDelegate> delegate;
@private
    NSMutableArray *cells;
}
@property (nonatomic) int row;
@property (nonatomic, assign) id<UIGridViewRowDelegate> delegate;
-(UIGridViewCell *)cellAtColumn:(NSUInteger)column;
-(void)addCell:(UIGridViewCell *)cell atColumn:(NSUInteger)column;
@end